package misp_backend.controller;

import com.alipay.api.domain.UserVo;
import io.swagger.annotations.ApiOperation;
import misp_backend.config.AjaxResult;
import misp_backend.domain.User;
import misp_backend.service.IMenuService;
import misp_backend.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/auth")
public class UserAuthController {
    private Long userId = 1L;
    @Autowired
    private UserService userService;
    @Autowired
    private IMenuService menuService;

    @PostMapping("/login")
    @ApiOperation("登录")
    public AjaxResult login(@RequestBody UserVo loginUserVo){
        Map<String, Object> data = new HashMap<>();
        data.put("token", "admin_token");
        return AjaxResult.success(data);
    }
    @ApiOperation("获取登录用户信息")
    @GetMapping("/getInfo")
    public AjaxResult getInfo() {
        Map<String, Object> data = new HashMap<>();
        User loginUser = userService.selectUserById(userId);
        data.put("name",loginUser.getNickName());
        data.put("avatar","https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        data.put("roles", userService.selectUserRoleGroup(loginUser));
        data.put("authorities",menuService.selectMenuPermsByUserId(loginUser.getUserId()));
        return AjaxResult.success(data);
    }
    @ApiOperation("退出登录")
    @GetMapping("/logout")
    public AjaxResult logout() {
        return AjaxResult.success("退出成功");
    }

    @ApiOperation("获取动态路由/SideBar菜单")
    @GetMapping("/getRouters")
    public AjaxResult getRouters(){
        return AjaxResult.success(menuService.getRouters(userId));
    }
}
